package com.hcy.rabbitbasicmodel.model;

import com.hcy.rabbitbasicmodel.enums.Code;
import lombok.Data;

import java.io.Serializable;

/**
 * @Author huchenying
 * Description:
 * @Date 2021/11/20 14:41
 */
@Data
public class ResponseData<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private Code code;
    private String msg;
    private T data;
    public ResponseData<T> success(T data){
        this.code = Code.Success;
        this.msg = "请求成功";
        this.data = data;
        return this;
    }
    public ResponseData<T> fail(){
        this.code = Code.Fail;
        this.msg = "请求失败";
        return this;
    }
    public ResponseData<T> fail(String msg){
        this.code = Code.Fail;
        this.msg = msg;
        return this;
    }
    public ResponseData<T>  exception(){
        this.code = Code.Exception;
        this.msg = "服务异常";
        return this;
    }
    public static ResponseData<Object> success(){
        ResponseData<Object> responseData = new ResponseData<>();
        responseData.setCode(Code.Success);
        return responseData;
    }
    public static ResponseData<Object> fail0(){
        ResponseData<Object> responseData = new ResponseData<>();
        responseData.setCode(Code.Fail);
        return responseData;
    }
    public static ResponseData<Object> fail0(String msg){
        ResponseData<Object> responseData = new ResponseData<>();
        responseData.setCode(Code.Fail);
        responseData.setMsg(msg);
        return responseData;
    }
}
